<?php


namespace App\Extensions\Actions\Upload;

use App\Models\AdminUser;
use App\PatentApply;
use Illuminate\Http\Request;
use Encore\Admin\Actions\Response;
use App\Extensions\Actions\RowAction;

class PatentCertUploadAction extends RowAction
{
    public $name = '授权后证书上传';

    public function handle(PatentApply $model, Request $request): Response
    {
        $model->storeFile($request->file('cert'), 'cert');
        return $this->response()->success('操作成功')->refresh();
    }

    public function form()
    {
        $this->file('cert', '证书')->required();
    }

    public function authorize(AdminUser $user, $model): bool
    {
        return $user->role_type == 1 || $user['id'] == $model['user_id'];
    }

}
